﻿using System;
using System.Collections.Generic;
using System.Text;

using RaisingStudio.Data.Common;
using RaisingStudio.Data.Common.Factories;
using RaisingStudio.Data.Expressions;
using RaisingStudio.Data.Common.Builders.Expressions;
using RaisingStudio.Data.Common.Managers;

namespace RaisingStudio.Data.Providers.Adapters
{
    /// <summary>
    /// DataItem DataAdapter.
    /// </summary>
    public partial class DataItemAdapter : DataAdapterBase, RaisingStudio.Data.Common.IDataItemAdapter
    {
        #region static member
        /// <summary>
        /// 从一个 DbDataReader object 中读取data.
        /// </summary>
        /// <param name="dataReader">A DbDataReader object.</param>
        /// <param name="sourceName">Column name.</param>
        /// <param name="dbType">Data type.</param>
        /// <returns>values.</returns>
        public static object GetDataReaderValue(System.Data.IDataReader dataReader, string sourceName, System.Data.DbType dbType)
        {
            int ordinal = dataReader.GetOrdinal(sourceName);
            if (dataReader.IsDBNull(ordinal))
            {
                return System.DBNull.Value;
            }
            else
            {
                object value = dataReader.GetValue(ordinal);
                switch (dbType)
                {
                    case System.Data.DbType.String:
                        {
                            return System.Convert.ToString(value);
                        }
                    case System.Data.DbType.Int32:
                        {
                            return System.Convert.ToInt32(value);
                        }
                    case System.Data.DbType.Boolean:
                        {
                            return System.Convert.ToBoolean(value);
                        }
                    case System.Data.DbType.Decimal:
                        {
                            return System.Convert.ToDecimal(value);
                        }
                    case System.Data.DbType.DateTime:
                        {
                            return System.Convert.ToDateTime(value);
                        }
                    case System.Data.DbType.Guid:
                        {
                            if(value is string)
                            {
                                return new System.Guid(value as string);
                            }
                            else if (value is byte[])
                            {
                                return new System.Guid(value as byte[]);
                            }
                            else
                            {
                                return value;
                            }
                        }
                    case System.Data.DbType.Single:
                        {
                            return System.Convert.ToSingle(value);
                        }
                    case System.Data.DbType.Double:
                        {
                            return System.Convert.ToDouble(value);
                        }
                    case System.Data.DbType.Byte:
                        {
                            return System.Convert.ToByte(value);
                        }
                    case System.Data.DbType.Int16:
                        {
                            return System.Convert.ToInt16(value);
                        }
                    case System.Data.DbType.Int64:
                        {
                            return System.Convert.ToInt64(value);
                        }
                    case System.Data.DbType.Binary:
                        {
                            return value;
                        }
                    case System.Data.DbType.Object:
                        {
                            return value;
                        }
                    // Unknown Type.
                    default:
                        {
                            //throw new System.NotSupportedException("Unknown Type.");
                            return value;
                        }
                }
            }
        }
        #endregion

        #region Common property 
        protected System.Type dataItemType;
        /// <summary>
        /// Type of data object.
        /// </summary>
        public System.Type DataItemType
        {
            get
            {
                return this.dataItemType;
            }
        }

        protected string definitionName;
        /// <summary>
        /// object definition name.
        /// </summary>
        public string DefinitionName
        {
            get
            {
                return this.definitionName;
            }
        }


        protected RaisingStudio.Data.Common.Builders.CommandBuilder commandBuilder;
        /// <summary>
        /// Command builder.
        /// </summary>
        public RaisingStudio.Data.Common.Builders.CommandBuilder CommandBuilder
        {
            get
            {
                if (this.commandBuilder == null)
                {
                    this.commandBuilder = CreateCommandBuilder();
                }
                return this.commandBuilder;
            }
        }

        protected System.Data.Common.DataTableMapping defaultDataTableMapping;
        /// <summary>
        /// default Data table mapping.
        /// </summary>
        public System.Data.Common.DataTableMapping DefaultDataTableMapping
        {
            get
            {
                if (this.defaultDataTableMapping == null)
                {
                    this.defaultDataTableMapping = this.CommandBuilder.CommonCommandBuilder.GetDataTableMapping();
                }
                return this.defaultDataTableMapping;
            }
        }

        protected bool cloneDataItem = true;
        /// <summary>
        /// Create same structure of Data item.
        /// </summary>
        public bool CloneDataItem
        {
            get
            {
                return this.cloneDataItem;
            }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataItemType">Type of data object.</param>
        public DataItemAdapter(System.Type dataItemType)
        {
            this.dataItemType = dataItemType;
            this.connection = ConnectionFactory.CreateConnection();
            DatabaseType databaseType;
            string providerName;
            ConnectionFactory.GetConnectionSetting(out databaseType, out providerName);
            this._databaseType = databaseType;
            this._providerName = providerName;
            this.transactionManager = TransactionManagerFactory.CreateTransactionManager(this.connection);
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataItemType">Type of data object.</param>
        /// <param name="connection">database connection.</param>
        public DataItemAdapter(System.Type dataItemType, System.Data.IDbConnection connection)
        {
            this.dataItemType = dataItemType;
            this.connection = connection;
            this.transactionManager = TransactionManagerFactory.CreateTransactionManager(this.connection);
        }

        public DataItemAdapter(System.Type dataItemType, System.Data.IDbConnection connection, DatabaseType databaseType, string providerName)
            : this(dataItemType, connection)
        {
            this._databaseType = databaseType;
            this._providerName = providerName;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataItemType">Type of data object.</param>
        /// <param name="transactionManager">database transaction manager.</param>
        public DataItemAdapter(System.Type dataItemType, TransactionManager transactionManager, ILogManager logManager)
        {
            this.dataItemType = dataItemType;
            this.transactionManager = transactionManager;
            this.connection = transactionManager.Connection;
            this._logManager = logManager;
        }

        public DataItemAdapter(System.Type dataItemType, TransactionManager transactionManager, DatabaseType databaseType, string providerName, ILogManager logManager)
            : this(dataItemType, transactionManager, logManager)
        {
            this._databaseType = databaseType;
            this._providerName = providerName;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataItemType">Type of data object.</param>
        /// <param name="definitionName">object definition name.</param>
        public DataItemAdapter(System.Type dataItemType, string definitionName)
            : this(dataItemType)
        {
            this.definitionName = definitionName;
        }

        public DataItemAdapter(System.Type dataItemType, string definitionName, DatabaseType databaseType, string providerName)
            : this(dataItemType, definitionName)
        {
            this._databaseType = databaseType;
            this._providerName = providerName;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataItemType">Type of data object.</param>
        /// <param name="definitionName">object definition name.</param>
        /// <param name="connection">database connection.</param>
        public DataItemAdapter(System.Type dataItemType, string definitionName, System.Data.IDbConnection connection)
            : this(dataItemType, connection)
        {
            this.definitionName = definitionName;
        }

        public DataItemAdapter(System.Type dataItemType, string definitionName, System.Data.IDbConnection connection, DatabaseType databaseType, string providerName)
            : this(dataItemType, definitionName, connection)
        {
            this._databaseType = databaseType;
            this._providerName = providerName;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataItemType">Type of data object.</param>
        /// <param name="definitionName">object definition name.</param>
        /// <param name="transactionManager">database transaction manager.</param>
        public DataItemAdapter(System.Type dataItemType, string definitionName, TransactionManager transactionManager, ILogManager logManager)
            : this(dataItemType, transactionManager, logManager)
        {
            this.definitionName = definitionName;
        }

        public DataItemAdapter(System.Type dataItemType, string definitionName, TransactionManager transactionManager, DatabaseType databaseType, string providerName, ILogManager logManager)
            : this(dataItemType, definitionName, transactionManager, logManager)
        {
            this._databaseType = databaseType;
            this._providerName = providerName;
        }
        #endregion

        #region Create Command
        /// <summary>
        /// Create a command builder.
        /// </summary>
        /// <returns>Command builder.</returns>
        public virtual RaisingStudio.Data.Common.Builders.CommandBuilder CreateCommandBuilder()
        {
            DatabaseType databaseType = GetDatabaseType();
#if !(PocketPC || Smartphone || WindowsCE)
            if (databaseType == DatabaseType.SHAREPOINT)
            {
                if (this.definitionName != null)
                {
                    return new RaisingStudio.Data.Common.Builders.SharePointCommandBuilder(this.connection, databaseType, this._providerName, this.dataItemType, this.definitionName);
                }
                else
                {
                    return new RaisingStudio.Data.Common.Builders.SharePointCommandBuilder(this.connection, databaseType, this._providerName, this.dataItemType);
                }
            }
            else
            {
#endif
                if (this.definitionName != null)
                {
                    return new RaisingStudio.Data.Common.Builders.CommandBuilder(this.connection, databaseType, this._providerName, this.dataItemType, this.definitionName);
                }
                else
                {
                    return new RaisingStudio.Data.Common.Builders.CommandBuilder(this.connection, databaseType, this._providerName, this.dataItemType);
                }
#if !(PocketPC || Smartphone || WindowsCE)
            }
#endif
        }

        public virtual DatabaseType GetDatabaseType()
        {
            if ((this._databaseType == DatabaseType.OTHER) && (!ProviderManager.Instance.ProviderExists(this._providerName)))
            {
                DatabaseType databaseType = ConnectionFactory.GetDatabaseType(this.connection);
                return databaseType;
            }
            return this._databaseType;
        }
        #endregion
        #region Create DataItem 
        /// <summary>
        /// Create Data item.
        /// </summary>
        /// <returns>Data item.</returns>
        private DataItem CreateDataItemInternal()
        {
            if (this.dataItemType.IsSubclassOf(typeof(RaisingStudio.Data.DataItem)))
            {
                return System.Activator.CreateInstance(this.dataItemType) as RaisingStudio.Data.DataItem;
            }
            else
            {
                return new RaisingStudio.Data.DataItem(this.dataItemType);
            }
        }

        protected RaisingStudio.Data.DataItem defaultDataItem;
        /// <summary>
        /// default Data item.
        /// </summary>
        public RaisingStudio.Data.DataItem DefaultDataItem
        {
            get
            {
                if (this.defaultDataItem == null)
                {
                    this.defaultDataItem = CreateDataItemInternal();
                }
                return this.defaultDataItem;
            }
        }

        /// <summary>
        /// Create Data item.
        /// </summary>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem CreateDataItem()
        {
            if (this.cloneDataItem)
            {
                return this.DefaultDataItem.Clone();
            }
            else
            {
                return CreateDataItemInternal();
            }
        }

        /// <summary>
        /// Create the list of data items.
        /// </summary>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList CreateDataItemList()
        {
            if (this.dataItemType.IsSubclassOf(typeof(RaisingStudio.Data.DataItem)))
            {
                System.Type listType = typeof(List<>);
                System.Type dataItemListType = listType.MakeGenericType(this.dataItemType);
                System.Collections.IList dataItemList = System.Activator.CreateInstance(dataItemListType) as System.Collections.IList;
                return dataItemList;
            }
            else
            {
                List<DataItem> dataItemList = new List<DataItem>();
                return dataItemList;
            }
        }
        #endregion

        #region Sets primary key value
        /// <summary>
        /// Sets Command The value of primary key.
        /// </summary>
        /// <param name="primaryKeyNames">primary key column name array.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="command">Command.</param>
        public static void SetPrimaryKeyValue(string[] primaryKeyNames, object[] primaryKeys, System.Data.IDbCommand command)
        {
            for (int i = 0; i < primaryKeyNames.Length; i++)
            {
                string columnName = primaryKeyNames[i];
                System.Data.IDbDataParameter originalMappingParameter = RaisingStudio.Data.Common.Builders.CommandBuilder.GetOriginalMappingParameterByColumn(command.Parameters, columnName);
                if (originalMappingParameter != null)
                {
                    originalMappingParameter.Value = primaryKeys[i];
                }
            }
        }

        /// <summary>
        /// Sets Command The value of primary key.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="command">Command.</param>
        protected virtual void SetPrimaryKeyValue(object[] primaryKeys, System.Data.IDbCommand command)
        {
            string[] primaryKeyNames = this.CommandBuilder.CommonCommandBuilder.GetPrimaryKeyNames();
            SetPrimaryKeyValue(primaryKeyNames, primaryKeys, command);
        }
        #endregion

        #region Transactions
        /// <summary>
        /// Begin Database transaction.
        /// </summary>
        /// <returns>The ID of transaction.</returns>
        public virtual string BeginTransaction()
        {
            return this.transactionManager.BeginTransaction();
        }

        /// <summary>
        /// Begin Database transaction.
        /// </summary>
        /// <param name="isolationLevel">Specifies the isolation level for the transaction.</param>
        /// <returns>The ID of transaction.</returns>
        public virtual string BeginTransaction(System.Data.IsolationLevel isolationLevel)
        {
            return this.transactionManager.BeginTransaction(isolationLevel);
        }

        /// <summary>
        /// Commit Database transaction.
        /// </summary>
        public virtual void CommitTransaction()
        {
            this.transactionManager.CommitTransaction();
        }

        /// <summary>
        /// Commit Database transaction.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        public virtual void CommitTransaction(string transactionID)
        {
            this.transactionManager.CommitTransaction(transactionID);
        }

        /// <summary>
        /// Rollback transaction.
        /// </summary>
        public virtual void RollbackTransaction()
        {
            this.transactionManager.RollbackTransaction();
        }

        /// <summary>
        /// Rollback transaction.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        public virtual void RollbackTransaction(string transactionID)
        {
            this.transactionManager.RollbackTransaction(transactionID);
        }
        #endregion

        #region protected methods
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The result of execute command.</returns>
        protected virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetConditionSelectCommand(out dataTableMapping);
            string[] columnNames = dataItem.ColumnNames;
            return Fill(command, dataTableMapping, dataItem, primaryKeys, columnNames, transaction);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The result of execute command.</returns>
        protected virtual int Fill(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            return Fill(dataItem, dataItem.PrimaryKeys, transaction);
        }

        public void SetParameterValue(object parameter, object value)
        {
            (parameter as System.Data.IDbDataParameter).Value = value;
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The result of execute command.</returns>
        protected int Fill(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            for (int i = 0; i < command.Parameters.Count; i++)
            {
                SetParameterValue(command.Parameters[i], primaryKeys[i]);
            }
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            try
            {
                if (dataReader.Read())
                {
                    foreach (string columnName in columnNames)
                    {
                        DataColumnDefinition dataColumnDefinition = this.CommandBuilder.CommonCommandBuilder.DataTableDefinition.Columns[columnName];
                        string sourceName = RaisingStudio.Data.Common.Builders.CommonCommandBuilder.GetDataColumnSourceColumn(dataTableMapping, columnName);
                        System.Data.DbType dbType = dataColumnDefinition.DbType;
                        dataItem[columnName] = GetDataReaderValue(dataReader, sourceName, dbType);
                    }
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }

            return dataReader.RecordsAffected;
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The result of execute command.</returns>
        protected virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetConditionSelectCommand(columnNames, out dataTableMapping);
            return Fill(command, dataTableMapping, dataItem, primaryKeys, columnNames, transaction);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The result of execute command.</returns>
        protected virtual int Fill(RaisingStudio.Data.DataItem dataItem, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            return Fill(dataItem, dataItem.PrimaryKeys, columnNames, transaction);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>Data item.</returns>
        protected virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, System.Data.IDbTransaction transaction)
        {
            RaisingStudio.Data.DataItem dataItem = CreateDataItem();
            Fill(dataItem, primaryKeys, transaction);
            return dataItem;
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>Data item.</returns>
        protected virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            Fill(dataItem, transaction);
            return dataItem;
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>Data item.</returns>
        protected virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            RaisingStudio.Data.DataItem dataItem = CreateDataItem();
            Fill(dataItem, primaryKeys, columnNames, transaction);
            return dataItem;
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>Data item.</returns>
        protected virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            Fill(dataItem, columnNames, transaction);
            return dataItem;
        }

        public static bool GetSourceColumnNullMapping(System.Data.IDbDataParameter parameter)
        {
            return DataParameterManager.GetSourceColumnNullMapping(parameter);
        }

        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Insert(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            System.Data.IDbCommand command = this.CommandBuilder.GetInsertCommand(this.DefaultDataTableMapping, false);
            foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            {
                if ((!GetSourceColumnNullMapping(parameter)) && (parameter.SourceVersion == System.Data.DataRowVersion.Current))
                {
                    object value = dataItem[parameter.SourceColumn];
                    if (value == null)
                    {
                        parameter.Value = System.DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = value;
                    }
                }
            }

            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            return RaisingStudio.Data.Common.Database.ExecuteNonQueryCommand(command);
        }

        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Insert(RaisingStudio.Data.DataItem dataItem, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping = this.CommandBuilder.CommonCommandBuilder.GetDataTableMapping(columnNames);
            System.Data.IDbCommand command = this.CommandBuilder.GetInsertCommand(dataTableMapping, false);
            foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            {
                if ((!GetSourceColumnNullMapping(parameter)) && (parameter.SourceVersion == System.Data.DataRowVersion.Current))
                {
                    string columnName = parameter.SourceColumn;
                    // 这句话好像也多余，因为前面create data Command 时已经给定了column name 数组了，Not 在columnNames中column 也Not 会在参数中出现。
                    //if (RaisingStudio.Data.Common.Builders.CommonCommandBuilder.ContainsValue(columnNames, columnName))
                    //{
                        object value = dataItem[columnName];
                        if (value == null)
                        {
                            parameter.Value = System.DBNull.Value;
                        }
                        else
                        {
                            parameter.Value = value;
                        }
                    //}
                }
            }

            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            return RaisingStudio.Data.Common.Database.ExecuteNonQueryCommand(command);
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Delete(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            #region 这样作多余了，因为primary key Not 能为Is null.
            //System.Data.IDbCommand command = this.CommandBuilder.GetDeleteCommand(this.DefaultDataTableMapping, false);
            //foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            //{
            //    object value = dataItem[parameter.SourceColumn];
            //    if (!GetSourceColumnNullMapping(parameter))
            //    {
            //        if ((value == null) || (value == System.DBNull.Value))
            //        {
            //            parameter.Value = System.DBNull.Value;
            //        }
            //        else
            //        {
            //            parameter.Value = value;
            //        }
            //    }
            //    else
            //    {
            //        if ((value == null) || (value == System.DBNull.Value))
            //        {
            //            parameter.Value = 1;
            //        }
            //    }
            //}

            //if (transaction != null)
            //{
            //    command.Transaction = transaction;
            //}
            //return RaisingStudio.Data.Common.Database.ExecuteNonQueryCommand(command);
            #endregion
            object[] primaryKeys = dataItem.PrimaryKeys;
            return Delete(primaryKeys, transaction);
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Delete(object[] primaryKeys, System.Data.IDbTransaction transaction)
        {
            System.Data.IDbCommand command = this.CommandBuilder.GetDeleteCommand(this.DefaultDataTableMapping, false);
            int i = 0;
            foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            {
                parameter.Value = primaryKeys[i];
                i++;
            }

            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            return RaisingStudio.Data.Common.Database.ExecuteNonQueryCommand(command);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Update(System.Data.Common.DataTableMapping dataTableMapping, RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            System.Data.IDbCommand command = this.CommandBuilder.GetUpdateCommand(dataTableMapping, false, false);
            foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            {
                if (!GetSourceColumnNullMapping(parameter))
                {
                    object value = dataItem[parameter.SourceColumn];
                    if (value == null)
                    {
                        parameter.Value = System.DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = value;
                    }
                }
            }

            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            return RaisingStudio.Data.Common.Database.ExecuteNonQueryCommand(command);
        }
   
        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Update(System.Data.Common.DataTableMapping dataTableMapping, object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            System.Data.IDbCommand command = this.CommandBuilder.GetUpdateCommand(dataTableMapping, false, false);
            int i = 0;
            foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            {
                if (!GetSourceColumnNullMapping(parameter))
                {
                    if (parameter.SourceVersion == System.Data.DataRowVersion.Original)
                    {
                        parameter.Value = primaryKeys[i];
                        i++;
                    }
                    else
                    {
                        object value = dataItem[parameter.SourceColumn];
                        if (value == null)
                        {
                            parameter.Value = System.DBNull.Value;
                        }
                        else
                        {
                            parameter.Value = value;
                        }
                    }
                }
            }

            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            return RaisingStudio.Data.Common.Database.ExecuteNonQueryCommand(command);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Update(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            return Update(this.DefaultDataTableMapping, dataItem, transaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            return Update(this.DefaultDataTableMapping, primaryKeys, dataItem, transaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Update(RaisingStudio.Data.DataItem dataItem, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping = this.CommandBuilder.CommonCommandBuilder.GetDataTableMapping(columnNames);
            return Update(dataTableMapping, dataItem, transaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping = this.CommandBuilder.CommonCommandBuilder.GetDataTableMapping(columnNames);
            return Update(dataTableMapping, primaryKeys, dataItem, transaction);
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        protected virtual bool Exists(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            object[] primaryKeys = dataItem.PrimaryKeys;
            return Exists(primaryKeys, transaction);
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        protected virtual bool Exists(object[] primaryKeys, System.Data.IDbTransaction transaction)
        {
            System.Data.IDbCommand command = this.CommandBuilder.GetExistsCommand(this.DefaultDataTableMapping);
            int i = 0;
            foreach (System.Data.IDbDataParameter parameter in command.Parameters)
            {
                parameter.Value = primaryKeys[i];
                i++;
            }

            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            WriteLog(command);
            int count = Convert.ToInt32(RaisingStudio.Data.Common.Database.ExecuteScalarCommand(command));
            return (count > 0) ? true : false;
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Save(RaisingStudio.Data.DataItem dataItem, System.Data.IDbTransaction transaction)
        {
            if (Exists(dataItem, transaction))
            {
                return Update(dataItem, transaction);
            }
            else
            {
                return Insert(dataItem, transaction);
            }
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        protected virtual int Save(RaisingStudio.Data.DataItem dataItem, string[] columnNames, System.Data.IDbTransaction transaction)
        {
            if (Exists(dataItem, transaction))
            {
                return Update(dataItem, columnNames, transaction);
            }
            else
            {
                return Insert(dataItem, columnNames, transaction);
            }
        }

        #region Batch Operation 
        /// <summary>
        /// Gets The name in database.
        /// </summary>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="sourceNames">data source name array.</param>
        /// <param name="dbTypes">data type 数组。</param>
        private void GetSourceNames(System.Data.Common.DataTableMapping dataTableMapping, string[] columnNames, out Dictionary<string, string> sourceNames, out Dictionary<string, System.Data.DbType> dbTypes)
        {
            sourceNames = new Dictionary<string, string>();
            dbTypes = new Dictionary<string, System.Data.DbType>();
            foreach (string columnName in columnNames)
            {
                DataColumnDefinition dataColumnDefinition = this.CommandBuilder.CommonCommandBuilder.DataTableDefinition.Columns[columnName];
                string sourceName = RaisingStudio.Data.Common.Builders.CommonCommandBuilder.GetDataColumnSourceColumn(dataTableMapping, columnName);
                System.Data.DbType dbType = dataColumnDefinition.DbType;
                sourceNames.Add(columnName, sourceName);
                dbTypes.Add(columnName, dbType);
            }
        }

        /// <summary>
        /// Fillthe list of data items.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="dataItemList">DataItem column 。</param>
        /// <returns>The result of execute command.</returns>
        protected int FillDataItemList(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, out System.Collections.IList dataItemList)
        {
            dataItemList = CreateDataItemList();
            RaisingStudio.Data.DataItem dataItem = CreateDataItem();
            string[] columnNames = dataItem.ColumnNames;

            Dictionary<string, string> sourceNames;
            Dictionary<string, System.Data.DbType> dbTypes;
            GetSourceNames(dataTableMapping, columnNames, out sourceNames, out dbTypes);

            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            int index = 0;
            try
            {
                while (dataReader.Read())
                {
                    foreach (string columnName in columnNames)
                    {
                        dataItem[columnName] = GetDataReaderValue(dataReader, sourceNames[columnName], dbTypes[columnName]);
                    }
                    dataItemList.Add(dataItem);
                    index++;

                    dataItem = CreateDataItem();
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }

            return index;
        }

        /// <summary>
        /// Fillthe list of data items.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="dataItemList">the list of data items.</param>
        /// <returns>The result of execute command.</returns>
        protected int FillDataItemList(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, string[] columnNames, out System.Collections.IList dataItemList)
        {
            dataItemList = CreateDataItemList();

            Dictionary<string, string> sourceNames;
            Dictionary<string, System.Data.DbType> dbTypes;
            GetSourceNames(dataTableMapping, columnNames, out sourceNames, out dbTypes);

            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            int index = 0;
            try
            {
                while (dataReader.Read())
                {
                    RaisingStudio.Data.DataItem dataItem = CreateDataItem();
                    foreach (string columnName in columnNames)
                    {
                        dataItem[columnName] = GetDataReaderValue(dataReader, sourceNames[columnName], dbTypes[columnName]);
                    }
                    dataItemList.Add(dataItem);
                    index++;
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }

            return index;
        }
    
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, out dataItemList);
            return dataItemList;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(string[] columnNames, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, columnNames, out dataItemList);
            return dataItemList;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(CommonCommand conditionCommand, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, out dataItemList);
            return dataItemList;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(string[] columnNames, CommonCommand conditionCommand, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, columnNames, out dataItemList);
            return dataItemList;
        }

        #region Paging Operation 
        /// <summary>
        /// Fillthe list of data items.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="dataObjectList">the list of data items.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>The result of execute command.</returns>
        protected int FillDataItemList(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, out System.Collections.IList dataItemList, int startRecord, int maxRecords)
        {
            dataItemList = CreateDataItemList();
            RaisingStudio.Data.DataItem dataItem = CreateDataItem();
            string[] columnNames = dataItem.ColumnNames;

            Dictionary<string, string> sourceNames;
            Dictionary<string, System.Data.DbType> dbTypes;
            GetSourceNames(dataTableMapping, columnNames, out sourceNames, out dbTypes);

            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            int index = 0;
            int count = 0;
            try
            {
                while ((dataReader.Read()) && (count < maxRecords))
                {
                    if (index >= startRecord)
                    {
                        foreach (string columnName in columnNames)
                        {
                            dataItem[columnName] = GetDataReaderValue(dataReader, sourceNames[columnName], dbTypes[columnName]);
                        }
                        dataItemList.Add(dataItem);
                        count++;
                        if (count < maxRecords)
                        {
                            dataItem = CreateDataItem();
                        }
                    }
                    index++;
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }

            return count;
        }

        /// <summary>
        /// Fillthe list of data items.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="dataItemList">the list of data items.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>The result of execute command.</returns>
        protected int FillDataItemList(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, string[] columnNames, out System.Collections.IList dataItemList, int startRecord, int maxRecords)
        {
            dataItemList = CreateDataItemList();

            Dictionary<string, string> sourceNames;
            Dictionary<string, System.Data.DbType> dbTypes;
            GetSourceNames(dataTableMapping, columnNames, out sourceNames, out dbTypes);

            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            int index = 0;
            int count = 0;
            try
            {
                while ((dataReader.Read()) && (count < maxRecords))
                {
                    if (index >= startRecord)
                    {
                        RaisingStudio.Data.DataItem dataItem = CreateDataItem();
                        foreach (string columnName in columnNames)
                        {
                            dataItem[columnName] = GetDataReaderValue(dataReader, sourceNames[columnName], dbTypes[columnName]);
                        }
                        dataItemList.Add(dataItem);
                        count++;
                    }
                    index++;
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }

            return count;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, out dataItemList, startRecord, maxRecords);
            return dataItemList;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(string[] columnNames, int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, columnNames, out dataItemList, startRecord, maxRecords);
            return dataItemList;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(CommonCommand conditionCommand, int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, out dataItemList, startRecord, maxRecords);
            return dataItemList;
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the list of data items.</returns>
        protected virtual System.Collections.IList GetDataList(string[] columnNames, CommonCommand conditionCommand, int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }
            System.Collections.IList dataItemList;
            FillDataItemList(command, dataTableMapping, columnNames, out dataItemList, startRecord, maxRecords);
            return dataItemList;
        }
        #endregion

        #region Enumerator
        /// <summary>
        /// Gets DataItem An array of Columns.
        /// </summary>
        /// <returns>An array of Columns.</returns>
        protected virtual string[] GetDataItemColumnNames()
        {
            RaisingStudio.Data.DataItem dataItem = CreateDataItem();
            string[] columnNames = dataItem.ColumnNames;
            return columnNames;
        }        

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="columnNames">column name column table.</param>
        /// <returns>the enumerator of data items.</returns>
        private System.Collections.IEnumerable GetEnumerator(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, string[] columnNames)
        {
            Dictionary<string, string> sourceNames;
            Dictionary<string, System.Data.DbType> dbTypes;
            GetSourceNames(dataTableMapping, columnNames, out sourceNames, out dbTypes);

            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            try
            {
                while (dataReader.Read())
                {
                    RaisingStudio.Data.DataItem dataItem = CreateDataItem();
                    foreach (string columnName in columnNames)
                    {
                        dataItem[columnName] = GetDataReaderValue(dataReader, sourceNames[columnName], dbTypes[columnName]);
                    }
                    yield return dataItem;
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }
        }
        
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(System.Data.IDbTransaction transaction)
        {
            string[] columnNames = GetDataItemColumnNames();
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(CommonCommand conditionCommand, System.Data.IDbTransaction transaction)
        {
            string[] columnNames = GetDataItemColumnNames();
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, CommonCommand conditionCommand, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames);
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="dataTableMapping">Data table mapping.</param>
        /// <param name="columnNames">column name column table.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        private System.Collections.IEnumerable GetEnumerator(System.Data.IDbCommand command, System.Data.Common.DataTableMapping dataTableMapping, string[] columnNames, int startRecord, int maxRecords)
        {
            Dictionary<string, string> sourceNames;
            Dictionary<string, System.Data.DbType> dbTypes;
            GetSourceNames(dataTableMapping, columnNames, out sourceNames, out dbTypes);

            WriteLog(command);
            System.Data.IDataReader dataReader = RaisingStudio.Data.Common.Database.ExecuteReaderCommand(command);
            int index = 0;
            int count = 0;
            try
            {
                while ((dataReader.Read()) && (count < maxRecords))
                {
                    if (index >= startRecord)
                    {
                        RaisingStudio.Data.DataItem dataItem = CreateDataItem();
                        foreach (string columnName in columnNames)
                        {
                            dataItem[columnName] = GetDataReaderValue(dataReader, sourceNames[columnName], dbTypes[columnName]);
                        }
                        yield return dataItem;
                        count++;
                    }
                    index++;
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            string[] columnNames = GetDataItemColumnNames();
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(CommonCommand conditionCommand, int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            string[] columnNames = GetDataItemColumnNames();
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transaction">Database transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        protected virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, CommonCommand conditionCommand, int startRecord, int maxRecords, System.Data.IDbTransaction transaction)
        {
            System.Data.Common.DataTableMapping dataTableMapping;
            System.Data.IDbCommand command = this.CommandBuilder.GetSelectCommand(columnNames, conditionCommand, out dataTableMapping);
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            return GetEnumerator(command, dataTableMapping, columnNames, startRecord, maxRecords);
        }
        #endregion
        #endregion
        #endregion
        #endregion

        #region Common Methods
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys)
        {
            return this.Fill(dataItem, primaryKeys, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem)
        {
            return this.Fill(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, string[] columnNames)
        {
            return this.Fill(dataItem, primaryKeys, columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.Fill(dataItem, columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys)
        {
            return this.GetData(primaryKeys, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem)
        {
            return this.GetData(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, string[] columnNames)
        {
            return this.GetData(primaryKeys, columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.GetData(dataItem, columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Insert(RaisingStudio.Data.DataItem dataItem)
        {
            return this.Insert(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Insert(RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.Insert(dataItem, columnNames, this.TransactionManager.DefaultTransaction);
        }
        
        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Delete(RaisingStudio.Data.DataItem dataItem)
        {
            return this.Delete(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Delete(object[] primaryKeys)
        {
            return this.Delete(primaryKeys, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(RaisingStudio.Data.DataItem dataItem)
        {
            return this.Update(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem)
        {
            return this.Update(primaryKeys, dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.Update(dataItem, columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.Update(primaryKeys, dataItem, columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        public virtual bool Exists(RaisingStudio.Data.DataItem dataItem)
        {
            return this.Exists(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        public virtual bool Exists(object[] primaryKeys)
        {
            return this.Exists(primaryKeys, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Save(RaisingStudio.Data.DataItem dataItem)
        {
            return this.Save(dataItem, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Save(RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.Save(dataItem, columnNames, this.TransactionManager.DefaultTransaction);
        }
      
        #region Batch Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList()
        {
            return GetDataList(this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames)
        {
            return GetDataList(columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(CommonCommand conditionCommand)
        {
            return GetDataList(conditionCommand, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, CommonCommand conditionCommand)
        {
            return GetDataList(columnNames, conditionCommand, this.TransactionManager.DefaultTransaction);
        }
        
        #region Paging Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(int startRecord, int maxRecords)
        {
            return GetDataList(startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, int startRecord, int maxRecords)
        {
            return GetDataList(columnNames, startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(CommonCommand conditionCommand, int startRecord, int maxRecords)
        {
            return GetDataList(conditionCommand, startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, CommonCommand conditionCommand, int startRecord, int maxRecords)
        {
            return GetDataList(columnNames, conditionCommand, startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }
        #endregion

        #region 迭代器
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator()
        {
            return GetEnumerator(this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames)
        {
            return GetEnumerator(columnNames, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(CommonCommand conditionCommand)
        {
            return GetEnumerator(conditionCommand, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, CommonCommand conditionCommand)
        {
            return GetEnumerator(columnNames, conditionCommand, this.TransactionManager.DefaultTransaction);
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(int startRecord, int maxRecords)
        {
            return GetEnumerator(startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, int startRecord, int maxRecords)
        {
            return GetEnumerator(columnNames, startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the enumerator of data objects.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data objects.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(CommonCommand conditionCommand, int startRecord, int maxRecords)
        {
            return GetEnumerator(conditionCommand, startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, CommonCommand conditionCommand, int startRecord, int maxRecords)
        {
            return GetEnumerator(columnNames, conditionCommand, startRecord, maxRecords, this.TransactionManager.DefaultTransaction);
        }
        #endregion
        #endregion
        #endregion
        #endregion

        #region Transaction
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, string transactionID)
        {
            return this.Fill(dataItem, primaryKeys, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Fill(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, string[] columnNames, string transactionID)
        {
            return this.Fill(dataItem, primaryKeys, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.Fill(dataItem, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, string transactionID)
        {
            return this.GetData(primaryKeys, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.GetData(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, string[] columnNames, string transactionID)
        {
            return this.GetData(primaryKeys, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.GetData(dataItem, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }
      
        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Insert(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Insert(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }
        
        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Insert(RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.Insert(dataItem, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Delete(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Delete(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Delete(object[] primaryKeys, string transactionID)
        {
            return this.Delete(primaryKeys, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Update(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Update(primaryKeys, dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.Update(dataItem, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.Update(primaryKeys, dataItem, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        public virtual bool Exists(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Exists(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        public virtual bool Exists(object[] primaryKeys, string transactionID)
        {
            return this.Exists(primaryKeys, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Save(RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Save(dataItem, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Save(RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.Save(dataItem, columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        #region Batch Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string transactionID)
        {
            return GetDataList(this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, string transactionID)
        {
            return GetDataList(columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(CommonCommand conditionCommand, string transactionID)
        {
            return GetDataList(conditionCommand, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, CommonCommand conditionCommand, string transactionID)
        {
            return GetDataList(columnNames, conditionCommand, this.TransactionManager.GetTransaction(transactionID));
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(int startRecord, int maxRecords, string transactionID)
        {
            return GetDataList(startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, int startRecord, int maxRecords, string transactionID)
        {
            return GetDataList(columnNames, startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(CommonCommand conditionCommand, int startRecord, int maxRecords, string transactionID)
        {
            return GetDataList(conditionCommand, startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, CommonCommand conditionCommand, int startRecord, int maxRecords, string transactionID)
        {
            return GetDataList(columnNames, conditionCommand, startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }
        #endregion

        #region 迭代器
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string transactionID)
        {
            return GetEnumerator(this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, string transactionID)
        {
            return GetEnumerator(columnNames, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(CommonCommand conditionCommand, string transactionID)
        {
            return GetEnumerator(conditionCommand, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, CommonCommand conditionCommand, string transactionID)
        {
            return GetEnumerator(columnNames, conditionCommand, this.TransactionManager.GetTransaction(transactionID));
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(int startRecord, int maxRecords, string transactionID)
        {
            return GetEnumerator(startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, int startRecord, int maxRecords, string transactionID)
        {
            return GetEnumerator(columnNames, startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(CommonCommand conditionCommand, int startRecord, int maxRecords, string transactionID)
        {
            return GetEnumerator(conditionCommand, startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, CommonCommand conditionCommand, int startRecord, int maxRecords, string transactionID)
        {
            return GetEnumerator(columnNames, conditionCommand, startRecord, maxRecords, this.TransactionManager.GetTransaction(transactionID));
        }
        #endregion
        #endregion
        #endregion
        #endregion

        #region Extension Functions
        #region Common Methods
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int FillByPrimaryKey(RaisingStudio.Data.DataItem dataItem, object primaryKey)
        {
            return this.Fill(dataItem, new object[] { primaryKey });
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int FillByPrimaryKey(RaisingStudio.Data.DataItem dataItem, object primaryKey, string[] columnNames)
        {
            return this.Fill(dataItem, new object[] { primaryKey }, columnNames);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByPrimaryKey(object primaryKey)
        {
            return this.GetData(new object[] { primaryKey });
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByPrimaryKey(object primaryKey, string[] columnNames)
        {
            return this.GetData(new object[] { primaryKey }, columnNames);
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByPrimaryKey(object primaryKey)
        {
            return this.Delete(new object[] { primaryKey });
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int UpdateByPrimaryKey(object primaryKey, RaisingStudio.Data.DataItem dataItem)
        {
            return this.Update(new object[] { primaryKey }, dataItem);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int UpdateByPrimaryKey(object primaryKey, RaisingStudio.Data.DataItem dataItem, string[] columnNames)
        {
            return this.Update(new object[] { primaryKey }, dataItem, columnNames);
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        public virtual bool ExistsByPrimaryKey(object primaryKey)
        {
            return this.Exists(new object[] { primaryKey });
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(CommonCommand conditionCommand)
        {
            System.Collections.IList dataList = GetDataList(conditionCommand, 0, 1);
            if (dataList.Count > 0)
            {
                return dataList[0] as RaisingStudio.Data.DataItem;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(string[] columnNames, CommonCommand conditionCommand)
        {
            System.Collections.IList dataList = GetDataList(columnNames, conditionCommand, 0, 1);
            if (dataList.Count > 0)
            {
                return dataList[0] as RaisingStudio.Data.DataItem;
            }
            else
            {
                return null;
            }
        }

        #region Epxression 
        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataByCondition(conditionCommand);
        }

        public ConditionExpressionCommandBuilder CreateConditionExpressionCommandBuilder(ConditionExpression conditionExpression)
        {
            Dictionary<string, System.Data.DbType> dbTypes = GetColumnsDbTypes();
            TableExpression tableExpression = GetTableExpression();
            return new ConditionExpressionCommandBuilder(conditionExpression, dbTypes, tableExpression);
        }

        private Dictionary<string, System.Data.DbType> GetColumnsDbTypes()
        {
            // TODO: 
            return this.CommandBuilder.CommonCommandBuilder.DbTypes;
        }

        private TableExpression GetTableExpression()
        {
            return new TableExpression(this.DefaultDataTableMapping.DataSetTable);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataByCondition(columnNames, conditionCommand);
        }

        #region Batch Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(conditionCommand);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(columnNames, conditionCommand);
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(conditionCommand, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(columnNames, conditionCommand, startRecord, maxRecords);
        }
        #endregion

        #region 迭代器
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(conditionCommand);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(columnNames, conditionCommand);
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the enumerator of data objects.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data objects.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(conditionCommand, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(columnNames, conditionCommand, startRecord, maxRecords);
        }
        #endregion
        #endregion
        #endregion

        #region column name Epxression 
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Fill(dataItem, primaryKeys, columnNames);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Fill(dataItem, columnNames);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.GetData(primaryKeys, columnNames);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.GetData(dataItem, columnNames);
        }

        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Insert(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Insert(dataItem, columnNames);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Update(dataItem, columnNames);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Update(primaryKeys, dataItem, columnNames);
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Save(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Save(dataItem, columnNames);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, int startRecord, int maxRecords)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, int startRecord, int maxRecords)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, startRecord, maxRecords);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int FillByPrimaryKey(RaisingStudio.Data.DataItem dataItem, object primaryKey, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Fill(dataItem, new object[] { primaryKey }, columnNames);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByPrimaryKey(object primaryKey, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.GetData(new object[] { primaryKey }, columnNames);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int UpdateByPrimaryKey(object primaryKey, RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Update(new object[] { primaryKey }, dataItem, columnNames);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataByCondition(columnNames, conditionExpression);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, conditionExpression);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, conditionExpression, startRecord, maxRecords);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, conditionExpression);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, conditionExpression, startRecord, maxRecords);
        }
        #endregion
        #endregion
        #endregion
        #region Transaction
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int FillByPrimaryKey(RaisingStudio.Data.DataItem dataItem, object primaryKey, string transactionID)
        {
            return this.Fill(dataItem, new object[] { primaryKey }, transactionID);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int FillByPrimaryKey(RaisingStudio.Data.DataItem dataItem, object primaryKey, string[] columnNames, string transactionID)
        {
            return this.Fill(dataItem, new object[] { primaryKey }, columnNames, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByPrimaryKey(object primaryKey, string transactionID)
        {
            return this.GetData(new object[] { primaryKey }, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByPrimaryKey(object primaryKey, string[] columnNames, string transactionID)
        {
            return this.GetData(new object[] { primaryKey }, columnNames, transactionID);
        }

        /// <summary>
        /// Delete Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByPrimaryKey(object primaryKey, string transactionID)
        {
            return this.Delete(new object[] { primaryKey }, transactionID);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int UpdateByPrimaryKey(object primaryKey, RaisingStudio.Data.DataItem dataItem, string transactionID)
        {
            return this.Update(new object[] { primaryKey }, dataItem, transactionID);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int UpdateByPrimaryKey(object primaryKey, RaisingStudio.Data.DataItem dataItem, string[] columnNames, string transactionID)
        {
            return this.Update(new object[] { primaryKey }, dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Check the data item exists or not.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>If exists then return true, otherwise return false.</returns>
        public virtual bool ExistsByPrimaryKey(object primaryKey, string transactionID)
        {
            return this.Exists(new object[] { primaryKey }, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(CommonCommand conditionCommand, string transactionID)
        {
            System.Collections.IList dataList = GetDataList(conditionCommand, 0, 1, transactionID);
            if (dataList.Count > 0)
            {
                return dataList[0] as RaisingStudio.Data.DataItem;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(string[] columnNames, CommonCommand conditionCommand, string transactionID)
        {
            System.Collections.IList dataList = GetDataList(columnNames, conditionCommand, 0, 1, transactionID);
            if (dataList.Count > 0)
            {
                return dataList[0] as RaisingStudio.Data.DataItem;
            }
            else
            {
                return null;
            }
        }

        #region Epxression 
        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataByCondition(conditionCommand, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataByCondition(columnNames, conditionCommand, transactionID);
        }

        #region Batch Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(conditionCommand, transactionID);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(columnNames, conditionCommand, transactionID);
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(conditionCommand, startRecord, maxRecords, transactionID);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetDataList(columnNames, conditionCommand, startRecord, maxRecords, transactionID);
        }
        #endregion

        #region 迭代器
        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(conditionCommand, transactionID);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(columnNames, conditionCommand, transactionID);
        }

        #region Paging Operation 
        /// <summary>
        /// Gets the enumerator of data objects.
        /// </summary>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data objects.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(conditionCommand, startRecord, maxRecords, transactionID);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnNames">An array of Columns.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(string[] columnNames, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords, string transactionID)
        {
            RaisingStudio.Data.Common.Builders.Expressions.ConditionExpressionCommandBuilder conditionExpressionCommandBuilder = CreateConditionExpressionCommandBuilder(conditionExpression);
            CommonCommand conditionCommand = conditionExpressionCommandBuilder.GetExpressionCommand();
            return GetEnumerator(columnNames, conditionCommand, startRecord, maxRecords, transactionID);
        }
        #endregion
        #endregion
        #endregion

        #region column name Epxression 
        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, object[] primaryKeys, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Fill(dataItem, primaryKeys, columnNames, transactionID);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int Fill(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Fill(dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(object[] primaryKeys, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.GetData(primaryKeys, columnNames, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="dataItem">Data item that contains primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetData(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.GetData(dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Insert Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Insert(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Insert(dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Update(dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(object[] primaryKeys, RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Update(primaryKeys, dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Save Data item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Save(RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Save(dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, transactionID);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, int startRecord, int maxRecords, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, startRecord, maxRecords, transactionID);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, transactionID);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, int startRecord, int maxRecords, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, startRecord, maxRecords, transactionID);
        }

        /// <summary>
        /// FillData item.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The result of execute command.</returns>
        public virtual int FillByPrimaryKey(RaisingStudio.Data.DataItem dataItem, object primaryKey, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Fill(dataItem, new object[] { primaryKey }, columnNames, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByPrimaryKey(object primaryKey, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.GetData(new object[] { primaryKey }, columnNames, transactionID);
        }

        /// <summary>
        /// Update Data item.
        /// </summary>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="dataItem">Data item.</param>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int UpdateByPrimaryKey(object primaryKey, RaisingStudio.Data.DataItem dataItem, ColumnExpression[] columnExpressions, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return this.Update(new object[] { primaryKey }, dataItem, columnNames, transactionID);
        }

        /// <summary>
        /// Gets Data item.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>Data item.</returns>
        public virtual RaisingStudio.Data.DataItem GetDataByCondition(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataByCondition(columnNames, conditionExpression, transactionID);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, conditionExpression, transactionID);
        }

        /// <summary>
        /// Gets the list of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the list of data items.</returns>
        public virtual System.Collections.IList GetDataList(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetDataList(columnNames, conditionExpression, startRecord, maxRecords, transactionID);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, conditionExpression, transactionID);
        }

        /// <summary>
        /// Gets the enumerator of data items.
        /// </summary>
        /// <param name="columnExpressions">An array of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="startRecord">The zero-based record number to start with. </param>
        /// <param name="maxRecords">The maximum number of records to retrieve. </param>
        /// <returns>the enumerator of data items.</returns>
        public virtual System.Collections.IEnumerable GetEnumerator(ColumnExpression[] columnExpressions, RaisingStudio.Data.Expressions.ConditionExpression conditionExpression, int startRecord, int maxRecords, string transactionID)
        {
            string[] columnNames = ConditionExpressionCommandBuilder.GetColumnNamesFromColumnExpressions(columnExpressions);
            return GetEnumerator(columnNames, conditionExpression, startRecord, maxRecords, transactionID);
        }
         #endregion
        #endregion
        #endregion
        #endregion
    }
}
